<!doctype html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>入学申请</title>
    <link rel="stylesheet" href="/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/css/scroll-bar.css">
    <link rel="stylesheet" href="/css/sub-page.css">
    <link rel="stylesheet" href="/lib/nprogress/nprogress.css">
</head>
<body>
<div class="ok-body">
    <!--面包屑导航区域-->
    <div class="ok-body-breadcrumb">
            <span class="layui-breadcrumb">
                <a><cite>首页</cite></a>
                <a><cite>招生就业</cite></a>
                <a><cite>入学申请</cite></a>
            </span>
        <a class="layui-btn layui-btn-sm" href="javascript:location.replace(location.href);" title="刷新">
            <i class="layui-icon layui-icon-refresh"></i>
        </a>
    </div>
    <!--数据表格-->
    <table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
</div>
<!--模板-->
<script type="text/html" id="statusTpl">
    <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="已处理|未处理" {{ d.status=== 1
           ? 'checked' : ''}}>
</script>
<script type="text/html" id="operationTpl">
    <a href="javascript:" title="删除" lay-event="del"><i class="layui-icon">&#xe640;</i></a></script>
<!--js逻辑-->
<script src="/lib/layui/layui.js"></script>
<script src="/lib/nprogress/nprogress.js"></script>
<script>
    // 进度条加载提示
    NProgress.start();
    window.onload = function () {
        NProgress.done();
    }
    // layui相关
    layui.use(['element', 'table', 'form', 'jquery', 'laydate', 'util'], function () {
        let element = layui.element;
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        // let util = layui.util;

        //渲染数据表格
        table.render({
            elem: '#tableId',
            url: '/manage/applies',
            limit: 10,
            page: true,
            even: true,
            cols: [[
                {field: 'id', title: 'ID', width: 80, sort: true},
                {field: 'name', title: '申请人', width: 100},
                {field: 'phone', title: '联系电话',width:120},
                {field: 'email', title: '邮箱', width:220},
                {field:'content',title:'留言内容'},
                {
                    field: 'applyDate',
                    title: '申请日期',
                    width: 160,
                    templet: "<div>{{layui.util.toDateString(d.applyDate, 'yyyy-MM-dd')}}</div>"
                },
                {field: 'status', title: '是否已处理', width: 120, templet: '#statusTpl'},
                {
                    field: 'processDate',
                    title: '处理日期',
                    width: 160,
                    templet: "<div>{{layui.util.toDateString(d.processDate, 'yyyy-MM-dd')}}</div>"
                },
                {title: '操作', fixed: 'right', width: 80, templet: '#operationTpl', align: 'center'}
            ]],
            done: function (res, curr, count) {
                $("#countNum").text(count);
            }
        });

        //表格工具列
        table.on('tool(tableFilter)', function (obj) {
            // var data = obj.data;
            let layEvent = obj.event;
            if (layEvent === 'del') {
                layer.confirm("确定要删除吗？", {skin: 'layui-layer-lan', icon: 2, title: '提示', anim: 6}, function () {
                    $.ajax({
                        url: '/manage/applies/' + obj.data.id,
                        type: 'DELETE',
                        dataType: 'json',
                        success: function (resp) {
                            if (resp) {
                                layer.msg("操作成功！", {icon: 1, time: 1000});
                                $(".layui-laypage-btn")[0].click();
                            }
                        }
                    })
                });
            }
        });

        //监听置顶、推荐、头图推荐操作
        form.on('switch', function (obj) {
            let status = 0;
            if (obj.elem.checked) {
                status = 1;
            }
            let data = '{"id":' + this.value + ',\"' + this.name + '\":' +status+ '}';
            $.ajax({
                url: '/manage/applies',
                data: data,
                dataType: 'json',
                contentType: 'application/json',
                type: 'PUT',
                success: function (resp) {
                    if (resp) {
                        layer.tips('操作成功', obj.othis);
                    } else {
                        layer.tips(resp.msg, obj.othis);
                    }
                }
            });
        });
    });
</script>

</body>
</html>